//
//  DGHorizontalLine.m
//  DGUIKit
//
//  Created by Jinxiao on 2/16/16.
//  Copyright © 2016 debugeek. All rights reserved.
//

#import "DGHorizontalLine.h"

@interface DGHorizontalLine ()
@property (readwrite, nonatomic, strong) CALayer *line;
@property (readwrite, nonatomic, assign) CGFloat lineWidth;
@end

@implementation DGHorizontalLine

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    if(_color == nil)
    {
        _color = [UIColor colorWithRGBHex:0xd2d2d2];
    }

    _lineWidth = 1/[UIScreen mainScreen].scale;
    
    _line = [self addBottomBorderWithColor:_color andWidth:_lineWidth];
    [self.layer addSublayer:_line];
}

- (void)setColor:(UIColor *)color
{
    _color = color;
    
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.backgroundColor = [UIColor clearColor];
    
    _line.backgroundColor = _color.CGColor;
    
    _line.frame = CGRectMake(0, (self.height - _lineWidth)/2, self.width, _lineWidth);
}

@end
